#include "doubly_linked_list.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

/*
typedef struct Node_t {
  Node_t *prev;
  Node_t *next;
  char data[0];
} Node;

typedef struct doubly_linked_list_t {
  Node *head;
  size_t size;
  size_t nmemb;
} DLList;

typedef int (*cmp_t)(const void *, const void *);
typedef void (*trave_t)(const void *);
*/
int DLList_init(DLList **list, size_t size) {
  *list = malloc(sizeof(DLList));
  if (*list == NULL) {
    return -1;
  }
  (*list)->head = NULL;
  (*list)->nmemb = 0;
  (*list)->size = size;
  return 1;
}
static Node *__new_node(size_t size, void *new_data) {
  Node *p = malloc(sizeof(Node) + size);
  if (p == NULL) {
    return NULL;
  }
  memcpy(p->data, new_data, size);
  p->next = NULL;
  p->prev = NULL;
  return p;
}

int DLList_insert_back(DLList *list, void *new_data) {
  if (list == NULL || new_data == NULL) {
    return -1;
  }
  Node *p = __new_node(list->size, new_data);
  if (p == NULL) {
    return -1;
  }
  if (list->nmemb == 0) {
    list->head->next = p;
    list->head
  }
}

int DLList_insert_front(DLList *list, void *new_data);

void *DLList_get(const DLList *list, size_t index);

int DLList_mod(DLList *list, size_t index, void *new_data);

int DLList_del(DLList *list, void *del_data, cmp_t cmp);

int DLList_search(const DLList *list, void *data, cmp_t cmp);

int DLList_free(DLList **list);

int DLList_trave(const DLList *list, trave_t trave);
